<template>
	<view class="userbank">
		<view class="info">
			<view class="info_input">
				<text>昵称</text>
				<input type="text" v-model="name" placeholder="请输入昵称" />
			</view>
		</view>
		<view class="btn" @click="changeName()">
			保存并使用
		</view>
	</view>
</template>

<script>
	import {
		Index,
		changeName
	} from '@/api/user.js'
	export default {
		data() {
			return {
				name: '',
			}
		},
		onLoad() {
			this.Index()
		},
		methods: {
			Index() {
				Index().then(res => {
					this.name = res.data.info.name
				})
			},
			changeName() {
				if (this.name == '') {
					uni.showToast({
						title: '请输入昵称',
						icon: 'none'
					})
					return false
				}
				changeName({
					name: this.name,

				}).then(res => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					if (res.status == 1) {
						setTimeout(res => {
							uni.navigateBack()
						}, 1000)
					}
				})

			},

		}
	}
</script>

<style lang="scss">
	.btn {
		box-shadow: 0rpx 5rpx 10rpx rgba(0, 0, 0, 0.4);
		width: 70%;
		height: 40px;
		border-radius: 40px;
		background-color: #f06c7a;
		color: #fff;
		justify-content: center;
		align-items: center;
		font-size: 15px;
		display: flex;
		margin: 30px auto;
	}

	.info {
		.title {
			padding: 5%;
			color: #000;
			font-size: 15px;
		}

		.info_input {
			background: #FFFFFF;
			padding: 5%;
			margin-bottom: 20rpx;
			display: flex;
			align-items: center;

			text {
				margin-right: 15px;
				font-size: 14px;
			}
		}
	}
</style>